/* 数据请求模块 */

import { Injectable } from '@angular/core';

import Hero from './hero'; // 引入数据模版
import { HEROES } from './mock-heroes'; // 导入模拟数据

@Injectable()

export class HeroService {
  getHeroes(): Promise<Hero[]> {
    return Promise.resolve(HEROES);
  };

  getHero(id: number): Promise<Hero> {
    return this.getHeroes()
            .then(heroes =>heroes.find(hero => hero.id === id));
  }
}
